﻿' •———————————————————————————————————————————————————————————————————————•
' | Copyright © 2011 Robert McGinley                                      |
' |                                                                       |
' | This program is free software: you can redistribute it and/or modify  |
' | it under the terms of the GNU General Public License as published by  |
' | the Free Software Foundation, either version 3 of the License, or     |
' | (at your option) any later version.                                   |
' |                                                                       |
' | This program is distributed in the hope that it will be useful,       |
' | but WITHOUT ANY WARRANTY; without even the implied warranty of        |
' | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
' | GNU General Public License for more details.                          |
' |                                                                       |
' | You should have received a copy of the GNU General Public License     |
' | along with this program.  If not, see <http://www.gnu.org/licenses/>. |
' •———————————————————————————————————————————————————————————————————————•

Imports System.IO
Imports Microsoft.Win32
Imports System.Windows
Imports SevenZip

Class MainWindow
    Public fileNamesList As List(Of String)
    Public badNamesList As List(Of String)

    Private Sub selectFile_Button_Click(ByVal sender As System.Object, ByVal e As RoutedEventArgs) Handles SelectFileButton.Click

        If FileModeRadioButton.IsChecked Then
            ' The user has selected the "File" radio button
            ' Set up our open file dialog and display for the user to select one or more files to extract
            ' Note: Each file will be treated as an independent archive in this mode
            Dim SelectFileDialog As OpenFileDialog = New OpenFileDialog
            SelectFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
            SelectFileDialog.Filter = "Compressed Archives|*.zip; *.rar; *.7z; *.gz; *.bz2|All Files|*.*"
            SelectFileDialog.FilterIndex = 1
            SelectFileDialog.Multiselect = True
            SelectFileDialog.Title = "Select Archive File(s)"
            SelectFileDialog.RestoreDirectory = True

            ' User selected one or more files
            If SelectFileDialog.ShowDialog() = True Then

                ' Put the selected filenames into a list
                fileNamesList.AddRange(SelectFileDialog.FileNames)

                'Run through each item in fileNamesList array and make sure they exist
                For Each fileName As String In fileNamesList
                    If Not My.Computer.FileSystem.FileExists(fileName) Then
                        'Remove the nonexistent file from the list of files
                        fileNamesList.Remove(fileName)

                        'Add it to another list so we can present it to the user
                        badNamesList.Add(fileName)

                    End If
                Next
            End If
        ElseIf DirectoryModeRadioButton.IsChecked Then
            Dim SelectDirectoryDialog As New WPFFolderBrowser.WPFFolderBrowserDialog
            SelectDirectoryDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop.ToString
            SelectDirectoryDialog.ShowPlacesList = True
            SelectDirectoryDialog.AddToMruList = True
            SelectDirectoryDialog.Title = "Select a folder"
            'Dim SelectedFolder As String = SelectDirectoryDialog.ShowDialog()
            Dim DirectoryDialogBoxResult As String = SelectDirectoryDialog.ShowDialog()
            If IsDBNull(DirectoryDialogBoxResult) OrElse DirectoryDialogBoxResult = False Then
                Exit Sub
            End If

            ' Checking if the directory exists based on the dialog box result has been moved to FileSystemFunctions.vb in the DirectoryExists method
            If DirectoryExists(DirectoryDialogBoxResult) = False Then
                ErrorMessage("Selected directory does not exist or cannot be found", "Directory not found")
                Exit Sub
            End If
            'We've validated the input, now we need to iterate all objects in the directory

        End If
    End Sub
End Class
